﻿<%@ Page Title="Анализ :: Пользователи" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="UserManagement.aspx.cs" Inherits="Analysis.UserManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#userDialog").dialog({ autoOpen: false, width: 900, resizable: false });
            $("#userDialog").parent().appendTo(jQuery("form:first"));

            $("#passwordDialog").dialog({ autoOpen: false, width: 800, resizable: false });
            $("#passwordDialog").parent().appendTo(jQuery("form:first"));

            $("#detailDialog").dialog({ autoOpen: false, width: 800, resizable: false });
            $("#detailDialog").parent().appendTo(jQuery("form:first"));

            $(".ui-dialog-titlebar").hide();

            <%=this.JsCodeToRunOnReady%>;
        });

        function createUpdateForm(id) {
            __doPostBack('upUserDetails', id);
        }

        function showPasswordChange(id)
        {
            $('#tbPassword').val('');
            $('#tbVerifyPassword').val('');
            $('#hdUserId1').val(id);
            $('.passwordValidator').hide();
            $('#passwordDialog').dialog('open');
        }

        function AutoComplete() {
            if ($('#MainContent_txtUserName').val() == '') {
                if ($('#MainContent_txtFirstName').val() != '') {
                    var fist_name_letter = $('#MainContent_txtFirstName').val()[0];
                    $('#MainContent_txtUserName').val(fist_name_letter + $('#MainContent_txtLastName').val());
                }
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
            <div class="page_header">
                <h2><img src="<%=ResolveClientUrl("~") %>images/design/user_management_tt_icon.png" alt="" title="" /> Пользователи</h2>
            </div>
            
            <asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            
        	<div class="page_container">
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnAdd" Text="Добавить" runat="server" OnClientClick="createUpdateForm(-1); return false;" />

                <div class="table-responsive">

                <asp:GridView ID="gridUsers" AutoGenerateColumns="false" runat="server" CssClass="table table-bordered table-hover"
                AllowPaging="True" PageSize="20" OnPageIndexChanging="gridUsers_PageIndexChanging" OnRowDataBound="gridUsers_RowDataBound">
                <PagerSettings Mode="Numeric" PageButtonCount="4" NextPageText=">" PreviousPageText="<"  FirstPageText="<<" LastPageText=">>"/>
                <Columns>
                    <asp:TemplateField HeaderText="Фамилия">
                        <ItemTemplate>
                            <asp:HiddenField ID="hidId" Value='<%#Eval("Id")%>' runat="server" />
                            <asp:Label ID="lblLastName" Text='<%# Eval("LastName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Имя">
                        <ItemTemplate>
                            <asp:Label ID="lblFirstName" Text='<%# Eval("FirstName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Email">
                        <ItemTemplate>
                            <asp:Label ID="lblEmail" Text='<%# Eval("Email") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Телефон">
                        <ItemTemplate>
                            <asp:Label ID="lblPhone" Text='<%#Eval("Phone")%>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Должность">
                        <ItemTemplate>
                            <asp:Label ID="lblNameDepart" Text='<%# Eval("DepartName") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField HeaderText="Действия">
                        <ItemTemplate>
                            <a href='javascript:void(0)' onclick="javascript:createUpdateForm(<%#Eval("Id")%>);">
                                <img src="<%=ResolveClientUrl("~") %>images/design/actions_icon/edit_icon.png" alt="" title="Редактировать" border="0" />
                            </a>
                            <asp:ImageButton runat="server" ImageUrl="~/images/design/actions_icon/delete_icon.gif" ToolTip="Удалить" Style="vertical-align:middle;"
                                ID="btnDelete" OnCommand="Users_Command" CommandName="delete" CommandArgument='<%# Eval("Id")%>' OnClientClick="return confirm('Подтвердите удаление пользователя')" />
                            <a href='javascript:void(0)' onclick="javascript:showPasswordChange(<%#Eval("Id")%>);">
                                <img src="<%=ResolveClientUrl("~") %>images/design/actions_icon/password_icon.png" alt="" title="Изменить пароль" border="0" />
                            </a>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                </asp:GridView>
                </div>
            </div>

            </ContentTemplate>
            </asp:UpdatePanel>

            <div id="userDialog" class="row">
                <asp:UpdatePanel runat="server" ID="upUserDetails" OnLoad="upUserDetails_Load" UpdateMode="Conditional" ClientIDMode="Static">
                <ContentTemplate>
                    <div class="fieldset_block col-lg-9 page_area" style="width:100%;">
                        <fieldset>
                            <legend><h4><asp:Label runat="server" ID="lblDialogTitle"></asp:Label></h4></legend>
                            <div class="fieldset_cotent form-horizontal">
                                <asp:Label runat="server" ID="hdUserId" style="display:none;" />
                                <div class="row">
                                	<div class="col-lg-6">                                    
                                    	<div class="form-group">
                                        	<label class="col-lg-4 control-label">Имя</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" placeholder="Введите имя пользователя" ID="txtFirstName" ValidationGroup="newUser" runat="server" TabIndex="1" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="txtFirstName" runat="server" Text="*" ValidationGroup="newUser" CssClass="validation_message" />
                                                <asp:RegularExpressionValidator ID="revFirstName" runat="server" ControlToValidate="txtFirstName" Text="Максимальная длина 100 символов" ValidationGroup="newUser" CssClass="validation_message" ValidationExpression="^([\S\s]{1,100})$" />
                                            </div>
                                        </div>
                                    	<div class="form-group">
                                        	<label class="col-lg-4 control-label">Фамилия</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" placeholder="Введите фамилию пользователя" ID="txtLastName" ValidationGroup="newUser" runat="server" TabIndex="2" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="txtLastName" runat="server" Text="*" ValidationGroup="newUser" CssClass="validation_message" />
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtLastName" Text="Максимальная длина 100 символов" ValidationGroup="newUser" CssClass="validation_message" ValidationExpression="^([\S\s]{1,100})$" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Email</label>
                                            <div class="col-lg-8">
                                                <asp:TextBox CssClass="form-control" ID="txtEmail" ValidationGroup="newUser" placeholder="Введите Email пользователя" runat="server" TabIndex="3" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtEmail" runat="server" ValidationGroup="newUser" Text="*" CssClass="validation_message" />
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ValidationGroup="newUser" ControlToValidate="txtEmail" runat="server" Text="Неверный e-mail" ForeColor="Red" />
                                            </div>
                                        </div>                                                                  
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Телефон</label>
                                            <label class="col-lg-1 control-label">+7</label>
                                            <div class="col-lg-7">
                                                <asp:TextBox CssClass="form-control" ID="txtPhone" ValidationGroup="newUser" placeholder="Введите телефон пользователя" runat="server" TabIndex="4" />
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="txtPhone" runat="server" ValidationGroup="newUser" Text="*" CssClass="validation_message" />
                                                <asp:RegularExpressionValidator ID="RegularExpressionValidator4" Display="Dynamic" ValidationExpression="[\d\s-]*" ValidationGroup="newUser" ControlToValidate="txtPhone" runat="server" Text="Неверный телефон" CssClass="validation_message" />
                                                <asp:CustomValidator id="CustomValidator1" runat="server" Display="Dynamic" OnServerValidate="PhoneValidate" ControlToValidate="txtPhone" ValidationGroup="newUser" ErrorMessage="Неверный телефон" CssClass="validation_message"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Должность</label>
                                            <div class="col-lg-8">
                                                <asp:DropDownList CssClass="form-control" ID="ddlDepart" runat="server" DataTextField="DepartName" DataValueField="DepartId" TabIndex="5"/>
                                                <asp:CompareValidator id="CompareValidator" runat="server" ControlToValidate="ddlDepart" ValidationGroup="newUser" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message"></asp:CompareValidator>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                        	<label class="col-lg-4 control-label">Как связать с АП</label>
                                            <div class="col-lg-8">
                                                <asp:RadioButton ID="rbIsFullAccessNot" runat="server" GroupName="AP" Text="На основании должности" /><br/>
                                                <asp:RadioButton ID="rbIsFullAccess" runat="server" GroupName="AP" Text="Полный доступ" />
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="col-lg-6">      
                                        
                                        <div class="form-group">
                                        	<label class="col-lg-12 control-label" style="text-align:left">Укажите, к каким страницам<br/> пользователь имеет доступ: </label>
                                        </div>
                                        
                                        <div class="form-group">
                                        	<div class="col-lg-12">
                                                <asp:CheckBox ID="chbIsPageReport" runat="server" Text="Отчеты" /><br/>
                                                <asp:CheckBox ID="chbIsPageAddress" runat="server" Text="Адресная программа" /><br/>
                                                <asp:CheckBox ID="chbIsPageAssort" runat="server" Text="Ассортимент" /><br/>
                                                <asp:CheckBox ID="chbIsPageMML" runat="server" Text="MML" /><br/>
                                                <asp:CheckBox ID="chbIsPageSale" runat="server" Text="Продажи" /><br/>
                                                <asp:CheckBox ID="chbIsPageUser" runat="server" Text="Пользователи" /><br/>
                                                <asp:CheckBox ID="chbIsPageSetup" runat="server" Text="Настройки системы" /><br/>
                                            </div>
                                        </div>                                        
                                    </div>
                                    
                                </div>
                                <div class="button_group">
                                    <asp:Button CssClass="btn btn-success" ID="btnSaveUser"  ValidationGroup="newUser" Text="Сохранить" runat="server" OnClick="btnSaveUser_Click" />
                                    <asp:Button CssClass="btn btn-info" ID="btnCancel" Text="Отмена" runat="server" OnClientClick="$('#userDialog').dialog('close'); return false;" />                                    
                                    <button class="btn btn-warning pull-right" type="button" id="lnkChangePassword" runat="server">Изменить пароль</button>
                                </div> 
                            </div>
                        </fieldset>
                    </div>
                </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnSaveUser" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
 
            <div id="passwordDialog" class="row">
            <asp:UpdatePanel runat="server" ID="upChangePassword" UpdateMode="Conditional" ClientIDMode="Static">
            <ContentTemplate>
                <div class="fieldset_block col-lg-9 page_area" style="width:100%;">
                <fieldset>
                    <legend><h4>Изменение пароля</h4></legend>
                    <div class="fieldset_cotent form-horizontal">
                        <asp:HiddenField runat="server" ID="hdUserId1" ClientIDMode="Static"/>
                        <div class="row">
                            <div class="col-lg-12">                                    
                                <div class="form-group">
                                    <label class="col-lg-4 control-label">Новый пароль</label>
                                    <div class="col-lg-3">
                                        <asp:TextBox ID="tbPassword" runat="server" TextMode="Password" CssClass="form-control" ClientIDMode="Static"></asp:TextBox>
                                    </div>
                                    <div class="col-lg-5">
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbPassword" 
                                            Display="Dynamic" ErrorMessage="*" ValidationGroup="changePassword" CssClass="validation_message"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="tbPassword" 
                                            Display="Dynamic" ErrorMessage="Разрешены латинские буквы и цифры, от 5 до 15 символов)" CssClass="validation_message"
                                            ValidationExpression="^[a-zA-Z0-9\s]{5,15}$" ValidationGroup="changePassword"></asp:RegularExpressionValidator>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-4 control-label">Новый пароль (повторно)</label>
                                    <div class="col-lg-3">
                                        <asp:TextBox ID="tbVerifyPassword" runat="server" TextMode="Password" CssClass="form-control" ClientIDMode="Static"></asp:TextBox>
                                    </div>
                                    <div class="col-lg-5">
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbVerifyPassword" 
                                            Display="Dynamic" ErrorMessage="*" ValidationGroup="changePassword" CssClass="validation_message"></asp:RequiredFieldValidator>
                                        <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="tbPassword"
                                            ControlToValidate="tbVerifyPassword" Display="Dynamic" 
                                            ErrorMessage="Введенные пароли не совпадают" 
                                            ValidationGroup="changePassword" CssClass="validation_message"></asp:CompareValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="button_group">
                            <asp:Button CssClass="btn btn-success" ID="btnSavePassword"  ValidationGroup="changePassword" Text="Сохранить" runat="server" OnClick="btnSavePassword_Click" />
                            <asp:Button CssClass="btn btn-info" ID="btnCancelPassword" Text="Отмена" runat="server" OnClientClick="$('#passwordDialog').dialog('close'); return false;" CausesValidation="false" />
                        </div> 
                    </div>
                </fieldset>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSavePassword" EventName="Click" />
            </Triggers>
            </asp:UpdatePanel>
            </div>

            <div id="detailDialog" class="row" style="display:none">
                <asp:UpdatePanel runat="server" ID="up_UserInformationDetail" UpdateMode="Conditional" ClientIDMode="Static">
                <ContentTemplate>
                    <div class="fieldset_block col-lg-12 page_area">
                        <fieldset>
                            <legend><h4><asp:Label runat="server" ID="lbldetailDialog"></asp:Label></h4></legend>
                            <div class="fieldset_cotent form-horizontal">
                                <asp:Label runat="server" ID="Label2" style="display:none;" />
                                <div class="row">                                    
                                    <asp:Label ID="UserNameDetail_text" runat="server"></asp:Label>
                                    <br />
                                    <asp:Label ID="UserPasswordDetail_text" runat="server"></asp:Label>
                                </div>
                                <div class="button_group">
                                    <asp:Button CssClass="btn btn-info" ID="Button2" Text="Закрыть" runat="server" OnClientClick="$('#detailDialog').dialog('close')" />                                    
                                </div> 
                            </div>
                        </fieldset>
                    </div>
                </ContentTemplate>
                </asp:UpdatePanel>
            </div>

</asp:Content>
